#!/bin/bash
#sudo ln -fs /bin/bash /bin/sh
#sh -x test.sh即bash -x test.sh调试sh文件
#sh test.sh即bash test.sh用bash执行文件
#获取真实sh路径, 判断是否需要处理
real_cmd=$(readlink -f /bin/sh)
echo "==readlink -f /bin/sh: $real_cmd"
if [ "$real_cmd" != "/bin/bash" ]; then
    echo "==sudo ln -fs /bin/bash /bin/sh"
    sudo ln -fs /bin/bash /bin/sh
fi

#一般是在.gitignore 文件里面加入 .idea/ workspace.xml 即可 
#但是如果你这样做之前已经将此文件提交到了git远程仓库，那就需要执行以下命令了： 
#git rm -r --cached .idea 
#git rm -r --cached .idea\/workspace.xml 

#有一个参数则设置参数,
project_name="yoshop"
netdisk_path="/mnt/d/syncdisk/"
#待压缩的文件, -v取不含-E后的关键字, -w完全匹配关键字
zip_files=`ls -a | grep -v -w -E "$project_name.7z|unpackage|apks|.git|.dart_tool|nodejs" | tr "\n" " " | sed "s/^. .. //"`
#去掉. .. 这5个字符
# zip_files=${zip_files:5}
echo $zip_files
#du -sh $zip_files
#echo $zip_files
#exit
if [ $# -eq 1 ]; then
	if [ "$1" = "noapp" ]; then
		version=""
	else
		version=".$1"
	fi
else
#没有参数为空
	version=""
fi
#回到$project_name根目录
echo "当前目录=$pwd"
#cd ../
echo "    \"git add .\""
git add .
echo "    \"git commit -m 'update'\""
git commit -m "update"
echo "    \"git push\""
git push
#git archive --format=zip --output master.zip master
rm $project_name.7z
echo "    \"7z a $project_name$version.7z files...\""
#压缩的文件, -xr"!build"排除build/, -xr"!go/build"排除go/build
7z a -t7z $project_name.7z $zip_files -xr"!go/build/*" -xr"!build/*" > /dev/null 2>&1
ls -lh $project_name.7z
#7z a $project_name.7z mprop python shell autojs docs flutter_doc win10_startup.bat android $project_name.iml .flutter-plugins .gitignore .idea images ios lib test .metadata .packages pubspec.yaml > /dev/null 2>&1
tmp=`date +"%Y.%m.%d_%H%M%S"`
echo "    \"上传${project_name}_$tmp$version.7z数据到netdisk\""
cp $project_name.7z $netdisk_path/${project_name}_$tmp$version.7z
echo "    \"上传${project_name}_$tmp$version.7z数据到网盘\""
#bypy upload $project_name.7z /flutter/${project_name}_$tmp$version.7z
